package com.hanyxx.thread;

import lombok.Data;
/**
 * 模拟stop产生数据不同步问题
 * @author layman
 * @date 2021/2/4
 */
public class ThreadStop {
    public static void main(String[] args) throws InterruptedException {
        User user = new User();
        ThreadDemo03 t = new ThreadDemo03(user);
        System.out.println(user);
        t.start();
        Thread.sleep(1000);
        t.stop();
        System.out.println("----------------------------------");
        System.out.println(user);
    }
}
class ThreadDemo03 extends Thread{
    private User user;
    public ThreadDemo03(User user){
        this.user = user;
    }
    @Override
    public void run() {
        try {
            user.setNameAndPassword("大帅哥","54321");
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
@Data
class User{
    private String name = "layman";
    private String password = "12345";

    public void setNameAndPassword(String name,String password) throws InterruptedException {
        this.name = name;
        Thread.sleep(3000);
        this.password = password;
    }
}
